#include "ManageClubDB.h"
#include "LogComm.h"
#include "globe.h"
#include "servant/Application.h"
#include "SocialServant.h"
#include "ServiceDefine.h"
#include "SocialServer.h"
#include "TimeUtil.h"

using namespace dataproxy;

// 检查俱乐部名字唯一性
tars::Int32 ManageClubCheckNameExist(const DBAgentServantPrx prx, string sClubName)
{
    FUNC_ENTRY("");
    int iRet = 0;
     __TRY__

    if (!prx)
    {
        ROLLLOG_ERROR << "ManageClubCheckNameExist prx null!" << endl;
        return -1;
    }

    dataproxy::TReadDataReq dataReq;
    dataReq.resetDefautlt();
    dataReq.keyName = I2S(E_REDIS_TYPE_HASH) + ":" + I2S(CLUB_INFO_CHECK_NAME) + ":" + sClubName;
    dataReq.operateType = E_REDIS_COUNT;
    dataReq.clusterInfo.resetDefautlt();
    dataReq.clusterInfo.busiType = E_REDIS_PROPERTY;
    dataReq.clusterInfo.frageFactorType = E_FRAGE_FACTOR_STRING;
    dataReq.clusterInfo.frageFactor = tars::hash<string>()(sClubName);

    TReadDataRsp dataRsp;
    iRet = prx->redisRead(dataReq, dataRsp);
    if(iRet != 0 || dataRsp.iResult != 0)
    {
        ROLLLOG_ERROR << "ManageClubCheckNameExist failed!" << " iRet:" << iRet << ", iResult:" << dataRsp.iResult << ", dataReq:" << printTars(dataReq) << endl;
        return -2;
    }

    ROLLLOG_DEBUG << "ManageClubCheckNameExist ok!" << " dataReq:" << printTars(dataReq) << ", dataRsp:" << printTars(dataRsp) << endl;

    if (dataRsp.totalcount > 0)
    {
        return -1;
    }

    __CATCH__

    FUNC_EXIT("", iRet);

    return iRet;
}

// 检查俱乐部ID唯一性
tars::Int32 ManageClubCheckIdExist(const DBAgentServantPrx prx, tars::Int64 cId)
{
    FUNC_ENTRY("");
    int iRet = 0;
     __TRY__

    if (!prx)
    {
        ROLLLOG_ERROR << "ManageClubCheckIdExist prx null!" << endl;
        return -1;
    }

    dataproxy::TReadDataReq dataReq;
    dataReq.resetDefautlt();
    dataReq.keyName = I2S(E_REDIS_TYPE_HASH) + ":" + I2S(CLUB_INFO_CHECK_CID) + ":" + L2S(cId);
    dataReq.operateType = E_REDIS_COUNT;
    dataReq.clusterInfo.resetDefautlt();
    dataReq.clusterInfo.busiType = E_REDIS_PROPERTY;
    dataReq.clusterInfo.frageFactorType = E_FRAGE_FACTOR_USER_ID;
    dataReq.clusterInfo.frageFactor = cId;

    TReadDataRsp dataRsp;
    iRet = prx->redisRead(dataReq, dataRsp);
    if(iRet != 0 || dataRsp.iResult != 0)
    {
        ROLLLOG_ERROR << "ManageClubCheckIdExist failed!" << " iRet:" << iRet << ", iResult:" << dataRsp.iResult << ", dataReq:" << printTars(dataReq) << endl;
        return -1;
    }

    ROLLLOG_DEBUG << "ManageClubCheckIdExist ok!" << " dataReq:" << printTars(dataReq) << ", dataRsp:" << printTars(dataRsp) << endl;

    if (dataRsp.totalcount > 0)
    {
        return -1;
    }

    __CATCH__
    FUNC_EXIT("", iRet);

    return iRet;
}

// 生成俱乐部ID
tars::Int32 ManageClubGetID(const DBAgentServantPrx prx, tars::Int64 &cId)
{
    FUNC_ENTRY("");
    int iRet = 0;
    __TRY__

    if (!prx)
    {
        ROLLLOG_ERROR << "ManageClubGetID prx null!" << endl;
        return -1;
    }

    int count = 0;
    do
    {
        count++;
        if (count > 100)
        {
            return -1;
        }
        cId = tars::Int64(timeutil::randomNumber(100001, 999999));

        iRet = ManageClubCheckIdExist(prx, cId);
    }while(iRet != 0);

    __CATCH__
    FUNC_EXIT("", iRet);

    return iRet;
}

// 生成俱乐部
tars::Int32 ManageClubCreate(const DBAgentServantPrx prx, tars::Int64 uId, tars::Int64 cId, std::string name, std::string country)
{
    FUNC_ENTRY("");
    int iRet = 0;
     __TRY__

    if (!prx)
    {
        ROLLLOG_ERROR << "ManageClubCreate prx null!" << endl;
        return -1;
    }

    dataproxy::TWriteDataReq dataReq;
    dataReq.resetDefautlt();
    dataReq.keyName = I2S(E_REDIS_TYPE_HASH) + ":" + I2S(CLUB_INFO) + ":" + L2S(cId);
    dataReq.operateType = E_REDIS_INSERT;
    dataReq.clusterInfo.resetDefautlt();
    dataReq.clusterInfo.busiType = E_REDIS_PROPERTY;
    dataReq.clusterInfo.frageFactorType = E_FRAGE_FACTOR_USER_ID;
    dataReq.clusterInfo.frageFactor = cId;

    vector<TField> fields;
    TField tfield;
    tfield.colArithType = E_NONE;
    tfield.colName = "cid";
    tfield.colType = BIGINT;
    tfield.colValue = L2S(cId);
    fields.push_back(tfield);

    tfield.colName = "uid";
    tfield.colType = BIGINT;
    tfield.colValue = L2S(uId);
    fields.push_back(tfield);

    tfield.colName = "create_id";
    tfield.colType = BIGINT;
    tfield.colValue = L2S(uId);
    fields.push_back(tfield);

    tfield.colName = "status";
    tfield.colType = INT;
    tfield.colValue = I2S(0);
    fields.push_back(tfield);

    tfield.colName = "dalao";
    tfield.colType = INT;
    tfield.colValue = I2S(0);
    fields.push_back(tfield);

    tfield.colName = "balance";
    tfield.colType = BIGINT;
    tfield.colValue = L2S(0);
    fields.push_back(tfield);

    tfield.colName = "merchant_level";
    tfield.colType = INT;
    tfield.colValue = I2S(0);
    fields.push_back(tfield);

    tfield.colName = "fund";
    tfield.colType = BIGINT;
    tfield.colValue = L2S(0);
    fields.push_back(tfield);

    tfield.colName = "country";
    tfield.colType = STRING;
    tfield.colValue = country;
    fields.push_back(tfield);

    tfield.colName = "logo";
    tfield.colType = STRING;
    tfield.colValue = "";
    fields.push_back(tfield);

    tfield.colName = "name";
    tfield.colType = STRING;
    tfield.colValue = name;
    fields.push_back(tfield);

    tfield.colName = "notice";
    tfield.colType = STRING;
    tfield.colValue = "";
    fields.push_back(tfield);

    tfield.colName = "level";
    tfield.colType = INT;
    tfield.colValue = I2S(1);
    fields.push_back(tfield);

    tfield.colName = "exp";
    tfield.colType = BIGINT;
    tfield.colValue = L2S(0);
    fields.push_back(tfield);

    tfield.colName = "is_show";
    tfield.colType = INT;
    tfield.colValue = I2S(1);
    fields.push_back(tfield);

    tfield.colName = "table_limit";
    tfield.colType = INT;
    tfield.colValue = I2S(1);
    fields.push_back(tfield);

    tfield.colName = "name_count";
    tfield.colType = INT;
    tfield.colValue = I2S(0);
    fields.push_back(tfield);

    tfield.colName = "level_limit";
    tfield.colType = INT;
    tfield.colValue = I2S(0);
    fields.push_back(tfield);

    tfield.colName = "time_limit";
    tfield.colType = INT;
    tfield.colValue = I2S(0);
    fields.push_back(tfield);

    tfield.colName = "created";
    tfield.colType = STRING;
    tfield.colValue = g_app.getOuterFactoryPtr()->GetTLogTimeFormat();
    fields.push_back(tfield);

    dataReq.fields = fields;

    dataproxy::TWriteDataRsp dataRsp;
    iRet = prx->redisWrite(dataReq, dataRsp);
    if (iRet != 0 || dataRsp.iResult != 0)
    {
        ROLLLOG_ERROR << "ManageClubGetClub failed! iRet:" << iRet << ", iResult:" << dataRsp.iResult << ", dataReq:" << printTars(dataReq) << endl;
        return -2;
    }

    ROLLLOG_DEBUG << "ManageClubGetClub ok!" << iRet << ", dataReq:" << printTars(dataReq) << endl;

    __CATCH__
    FUNC_EXIT("", iRet);

    return iRet;
}

// 更新俱乐部信息
tars::Int32 ManageClubModify(const DBAgentServantPrx prx, tars::Int64 cId, int flag, int status, std::string country, std::string logo, std::string name, std::string notice, int show, int tableLimit, int level, int levelDay, tars::Int64 uId)
{
    FUNC_ENTRY("");
    int iRet = 0;
     __TRY__

    if (!prx)
    {
        ROLLLOG_ERROR << "ManageClubModify prx null!" << endl;
        return -1;
    }

    dataproxy::TWriteDataReq dataReq;
    dataReq.resetDefautlt();
    dataReq.keyName = I2S(E_REDIS_TYPE_HASH) + ":" + I2S(CLUB_INFO_UPDATE) + ":" + L2S(cId);
    dataReq.operateType = E_REDIS_WRITE;
    dataReq.paraExt.resetDefautlt();
    dataReq.paraExt.queryType = dbagent::E_UPDATE;
    dataReq.clusterInfo.resetDefautlt();
    dataReq.clusterInfo.busiType = E_REDIS_PROPERTY;
    dataReq.clusterInfo.frageFactorType = E_FRAGE_FACTOR_USER_ID;
    dataReq.clusterInfo.frageFactor = cId;

    vector<TField> fields;
    TField tfield;
    tfield.colArithType = E_NONE;
    if (flag == 1)
    {
        tfield.colName = "country";
        tfield.colType = STRING;
        tfield.colValue = country;
        fields.push_back(tfield);
    }
    else if (flag == 2)
    {
        tfield.colName = "logo";
        tfield.colType = STRING;
        tfield.colValue = logo;
        fields.push_back(tfield);
    }
    else if (flag == 3)
    {
        tfield.colName = "name";
        tfield.colType = STRING;
        tfield.colValue = name;
        fields.push_back(tfield);

        tfield.colArithType = E_ADD;
        tfield.colName = "name_count";
        tfield.colType = INT;
        tfield.colValue = I2S(1);
        fields.push_back(tfield);
    }
    else if (flag == 4)
    {
        tfield.colName = "notice";
        tfield.colType = STRING;
        tfield.colValue = notice;
        fields.push_back(tfield);
    }
    else if (flag == 5)
    {
        tfield.colName = "is_show";
        tfield.colType = INT;
        tfield.colValue = I2S(show);
        fields.push_back(tfield);
    }
    else if (flag == 6)
    {
        tfield.colName = "table_limit";
        tfield.colType = INT;
        tfield.colValue = I2S(tableLimit);
        fields.push_back(tfield);
    }
    else if (flag == 7)
    {
        tfield.colName = "level";
        tfield.colType = INT;
        tfield.colValue = I2S(level);
        fields.push_back(tfield);

        tfield.colName = "level_limit";
        tfield.colType = INT;
        tfield.colValue = I2S(level);
        fields.push_back(tfield);

        int today = timeutil::todayBeginTime();
        today += levelDay * 24 * 60 *60;
        tfield.colName = "time_limit";
        tfield.colType = INT;
        tfield.colValue = I2S(today);
        fields.push_back(tfield);
    }
    else if (flag == 8)
    {
        tfield.colName = "uid";
        tfield.colType = BIGINT;
        tfield.colValue = L2S(uId);
        fields.push_back(tfield);
    }
    else if (flag == 9)
    {
        tfield.colName = "level";
        tfield.colType = INT;
        tfield.colValue = I2S(level);
        fields.push_back(tfield);
    }
    else
    {
        tfield.colName = "status";
        tfield.colType = INT;
        tfield.colValue = I2S(status);
        fields.push_back(tfield);
    }

    dataReq.fields = fields;

    dataproxy::TWriteDataRsp dataRsp;
    iRet = prx->redisWrite(dataReq, dataRsp);
    if (iRet != 0 || dataRsp.iResult != 0)
    {
        ROLLLOG_ERROR << "ManageClubModify failed! iRet:" << iRet << ", iResult:" << dataRsp.iResult << ", dataReq:" << printTars(dataReq) << endl;
        return -2;
    }

    ROLLLOG_DEBUG << "ManageClubModify ok! dataReq:" << printTars(dataReq) << endl;
    
    __CATCH__
    FUNC_EXIT("", iRet);

    return iRet;   
}

// 生成成员
tars::Int32 ManageClubCreateMember(const DBAgentServantPrx prx, tars::Int64 uid, tars::Int64 cId, tars::Int32 position)
{
    FUNC_ENTRY("");
    int iRet = 0;
     __TRY__

    if (!prx)
    {
        ROLLLOG_ERROR << "ManageClubCreateMember prx null!" << endl;
        return -1;
    }

    dataproxy::TWriteDataReq dataReq;
    dataReq.resetDefautlt();
    dataReq.keyName = I2S(E_REDIS_TYPE_LIST) + ":" + I2S(CLUB_MEMBER_CREATE) + ":" + L2S(uid);
    dataReq.operateType = E_REDIS_INSERT;
    dataReq.clusterInfo.resetDefautlt();
    dataReq.clusterInfo.busiType = E_REDIS_PROPERTY;
    dataReq.clusterInfo.frageFactorType = E_FRAGE_FACTOR_USER_ID;
    dataReq.clusterInfo.frageFactor = uid;

    vector<TField> fields;
    TField tfield;
    tfield.colArithType = E_NONE;
    tfield.colName = "cid";
    tfield.colType = BIGINT;
    tfield.colValue = L2S(cId);
    fields.push_back(tfield);

    tfield.colName = "uid";
    tfield.colType = BIGINT;
    tfield.colValue = L2S(uid);
    fields.push_back(tfield);

    tfield.colName = "position";
    tfield.colType = INT;
    tfield.colValue = I2S(position);
    fields.push_back(tfield);

    tfield.colName = "balance";
    tfield.colType = BIGINT;
    tfield.colValue = L2S(0);
    fields.push_back(tfield);

    tfield.colName = "locked";
    tfield.colType = BIGINT;
    tfield.colValue = L2S(1);
    fields.push_back(tfield);
    
    tfield.colName = "joined";
    tfield.colType = STRING;
    tfield.colValue = g_app.getOuterFactoryPtr()->GetTLogTimeFormat();
    fields.push_back(tfield);

    dataReq.fields = fields;

    dataproxy::TWriteDataRsp dataRsp;
    iRet = prx->redisWrite(dataReq, dataRsp);
    if (iRet != 0 || dataRsp.iResult != 0)
    {
        ROLLLOG_ERROR << "ManageClubCreateMember failed! iRet:" << iRet << ", iResult:" << dataRsp.iResult << ", dataReq:" << printTars(dataReq) << endl;
        return -2;
    }

    ROLLLOG_DEBUG << "ManageClubCreateMember ok! dataReq:" << printTars(dataReq) << endl;

    __CATCH__
    FUNC_EXIT("", iRet);

    return iRet;
}

// 删除成员
tars::Int32 ManageClubDeleteMember(const DBAgentServantPrx prx, tars::Int64 uId, tars::Int64 cId)
{
    FUNC_ENTRY("");
    int iRet = 0;
     __TRY__

    if (!prx)
    {
        ROLLLOG_ERROR << "ManageClubDeleteMember prx null!" << endl;
        return -1;
    }

    dataproxy::TWriteDataReq dataReq;
    dataReq.resetDefautlt();
    dataReq.keyName = I2S(E_REDIS_TYPE_LIST) + ":" + I2S(CLUB_MEMBER_DEL) + ":" + L2S(uId);
    dataReq.operateType = E_REDIS_WRITE;
    dataReq.paraExt.resetDefautlt();
    dataReq.paraExt.queryType = dbagent::E_DELETE;
    dataReq.clusterInfo.resetDefautlt();
    dataReq.clusterInfo.busiType = E_REDIS_PROPERTY;
    dataReq.clusterInfo.frageFactorType = E_FRAGE_FACTOR_USER_ID;
    dataReq.clusterInfo.frageFactor = uId;

    vector<TField> fields;
    TField tfield;
    auto &conditionFields = dataReq.paraExt.fields;
    tfield.resetDefautlt();
    tfield.colValue = L2S(cId);
    conditionFields["cid"] = tfield;
   
    dataproxy::TWriteDataRsp dataRsp;
    iRet = prx->redisWrite(dataReq, dataRsp);
    if (iRet != 0 || dataRsp.iResult != 0)
    {
        ROLLLOG_ERROR << "ManageClubDeleteMember failed! iRet:" << iRet << ", iResult:" << dataRsp.iResult << ", dataReq:" << printTars(dataReq) << endl;
        return -2;
    }

    ROLLLOG_DEBUG << "ManageClubDeleteMember ok! dataReq:" << printTars(dataReq) << endl;

    __CATCH__
    FUNC_EXIT("", iRet);

    return iRet;
}

// 获取俱乐部
tars::Int32 ManageClubGetClub(const DBAgentServantPrx prx, Club::ClubDBInfo &info, tars::Int64 cId)
{
    FUNC_ENTRY("");
    int iRet = 0;
     __TRY__

    if (!prx)
    {
        ROLLLOG_ERROR << "ManageClubGetClub prx null!" << endl;
        return -1;
    }

    dataproxy::TReadDataReq dataReq;
    dataReq.resetDefautlt();
    dataReq.keyName = I2S(E_REDIS_TYPE_LIST) + ":" + I2S(CLUB_INFO) + ":" + L2S(cId);
    dataReq.operateType = E_REDIS_READ;
    dataReq.clusterInfo.resetDefautlt();
    dataReq.clusterInfo.busiType = E_REDIS_PROPERTY;
    dataReq.clusterInfo.frageFactorType = E_FRAGE_FACTOR_STRING;
    dataReq.clusterInfo.frageFactor = tars::hash<string>()(L2S(cId));;

    TReadDataRsp dataRsp;
    iRet = prx->redisRead(dataReq, dataRsp);
    if(iRet != 0 || dataRsp.iResult != 0)
    {
        ROLLLOG_ERROR << "ManageClubGetClub failed! iRet:" << iRet << ", iResult:" << dataRsp.iResult << endl;
        return -2;
    }

    ROLLLOG_DEBUG << "ManageClubGetClub ok! dataRsp:" << printTars(dataRsp) << endl;

    for (auto it = dataRsp.fields.begin(); it != dataRsp.fields.end(); ++it)
    {
        for (auto itfield = it->begin(); itfield != it->end(); ++itfield)
        {
            if (itfield->colName == "cid")
            {
                info.cId = S2L(itfield->colValue);
            }
            else if (itfield->colName == "uid")
            {
                info.uId = S2L(itfield->colValue);
            }
            else if (itfield->colName == "created_id")
            {
                info.createdId = S2L(itfield->colValue);
            }
            else if (itfield->colName == "status")
            {
                info.status = S2I(itfield->colValue);
            }
            else if (itfield->colName == "dalao")
            {
                info.dalao = S2I(itfield->colValue);
            }
            else if (itfield->colName == "balance")
            {
                info.balance = S2L(itfield->colValue);
            }
            else if (itfield->colName == "merchant_level")
            {
                info.merchantLevel = S2I(itfield->colValue);
            }
            else if (itfield->colName == "fund")
            {
                info.fund = S2L(itfield->colValue);
            }
            else if (itfield->colName == "logo")
            {
                info.logo = itfield->colValue;
            }
            else if (itfield->colName == "name")
            {
                info.name = itfield->colValue;
            }
            else if (itfield->colName == "notice")
            {
                info.notice = itfield->colValue;
            }
            else if (itfield->colName == "level")
            {
                info.level = S2I(itfield->colValue);
            }
            else if (itfield->colName == "exp")
            {
                info.exp = S2L(itfield->colValue);
            }
            else if (itfield->colName == "is_show")
            {
                info.show = S2I(itfield->colValue);
            }
            else if (itfield->colName == "table_limit")
            {
                info.tableLimit = S2I(itfield->colValue);
            }
            else if (itfield->colName == "country")
            {
                info.country = itfield->colValue;
            }
            else if (itfield->colName == "name_count")
            {
                info.nameCount = S2I(itfield->colValue);
            }
            else if (itfield->colName == "level_limit")
            {
                info.levelLimit = S2I(itfield->colValue);
            }
            else if (itfield->colName == "time_limit")
            {
                info.timeLimit = S2I(itfield->colValue);
            }
            else if (itfield->colName == "created")
            {
                info.created = g_app.getOuterFactoryPtr()->GetCustomTimeTick(itfield->colValue);
            }
        }
    }

    // 弃用的俱乐部代表没有
    if (info.status == 1)
    {
        return -3;
    }

    __CATCH__
    FUNC_EXIT("", iRet);

    return iRet;
}

// 获取俱乐部成员
tars::Int32 ManageClubGetMember(const DBAgentServantPrx prx, Club::ClubDBMember &info, tars::Int64 uId, tars::Int64 cId)
{
    FUNC_ENTRY("");
    int iRet = 0;
     __TRY__

    if (!prx)
    {
        ROLLLOG_ERROR << "ManageClubGetMember prx null!" << endl;
        return -1;
    }

    dataproxy::TReadDataReq dataReq;
    dataReq.resetDefautlt();
    dataReq.keyName = I2S(E_REDIS_TYPE_LIST) + ":" + I2S(CLUB_MEMBER_DEL) + ":" + L2S(uId);
    dataReq.operateType = E_REDIS_READ;
    dataReq.clusterInfo.resetDefautlt();
    dataReq.clusterInfo.busiType = E_REDIS_PROPERTY;
    dataReq.clusterInfo.frageFactorType = E_FRAGE_FACTOR_STRING;
    dataReq.clusterInfo.frageFactor = tars::hash<string>()(L2S(uId));;

    vector<TField> fields;
    TField tfield;
    auto &conditionFields = dataReq.paraExt.fields;
    tfield.resetDefautlt();
    tfield.colValue = L2S(cId);
    conditionFields["cid"] = tfield;

    TReadDataRsp dataRsp;
    iRet = prx->redisRead(dataReq, dataRsp);
    if(iRet != 0 || dataRsp.iResult != 0)
    {
        ROLLLOG_ERROR << "ManageClubGetMember failed!" << " iRet:" << iRet << ", iResult:" << dataRsp.iResult << ", dataReq:" << printTars(dataReq) << endl;
        return -1;
    }

    ROLLLOG_DEBUG << "ManageClubGetMember ok!" << " dataReq:" << printTars(dataReq) << ", dataRsp" <<  printTars(dataRsp) << endl;

    for (auto it = dataRsp.fields.begin(); it != dataRsp.fields.end(); ++it)
    {
        for (auto itfield = it->begin(); itfield != it->end(); ++itfield)
        {
            if (itfield->colName == "cid")
            {
                info.cId = S2L(itfield->colValue);
            }
            else if (itfield->colName == "uid")
            {
                info.uId = S2L(itfield->colValue);
            }
            else if (itfield->colName == "balance")
            {
                info.balance = S2L(itfield->colValue);
            }
            else if (itfield->colName == "position")
            {
                info.position = S2I(itfield->colValue);
            }
            else if (itfield->colName == "locked")
            {
                info.locked = S2I(itfield->colValue);
            }
            else if (itfield->colName == "joined")
            {
                info.joined = g_app.getOuterFactoryPtr()->GetCustomTimeTick(itfield->colValue);
            }
        }
    }

    __CATCH__
    FUNC_EXIT("", iRet);

    return iRet;
}

// 检查创建俱乐部数量
tars::Int32 ManageClubGetCreatedCount(const DBAgentServantPrx prx, tars::Int64 uId, int &count)
{
    FUNC_ENTRY("");
    int iRet = 0;
     __TRY__

    if (!prx)
    {
        ROLLLOG_ERROR << "ManageClubGetCreatedCount prx null!" << endl;
        return -1;
    }

    dataproxy::TReadDataReq dataReq;
    dataReq.resetDefautlt();
    dataReq.keyName = I2S(E_REDIS_TYPE_HASH) + ":" + I2S(CLUB_INFO_CREATED_COUNT) + ":" + L2S(uId);
    dataReq.operateType = E_REDIS_COUNT;
    dataReq.clusterInfo.resetDefautlt();
    dataReq.clusterInfo.busiType = E_REDIS_PROPERTY;
    dataReq.clusterInfo.frageFactorType = E_FRAGE_FACTOR_USER_ID;
    dataReq.clusterInfo.frageFactor = uId;

    vector<TField> fields;
    dbagent::TField tfield;
    auto &conditionFields = dataReq.paraExt.fields;
    tfield.resetDefautlt();
    tfield.colValue = L2S(uId);
    conditionFields["create_id"] = tfield;
    tfield.colValue = I2S(0);
    conditionFields["dalao"] = tfield;

    TReadDataRsp dataRsp;
    iRet = prx->redisRead(dataReq, dataRsp);
    if(iRet != 0 || dataRsp.iResult != 0)
    {
        ROLLLOG_ERROR << "ManageClubGetCreatedCount failed!" << " iRet:" << iRet << ", iResult:" << dataRsp.iResult << ", dataReq:" << printTars(dataReq) << endl;
        return -2;
    }

    ROLLLOG_DEBUG << "ManageClubGetCreatedCount ok!" << " dataReq:" << printTars(dataReq) << ", dataRsp:" << printTars(dataRsp) << endl;

    if (dataRsp.totalcount > 0)
    {
        count = dataRsp.totalcount;
    }

    __CATCH__
    FUNC_EXIT("", iRet);

    return iRet;
}

// 获取创建加入的俱乐部ID与职位
tars::Int32 ManageClubGetClubIDAndPosition(const DBAgentServantPrx prx, tars::Int64 uId, std::map<long, int> &mClubIds)
{
    FUNC_ENTRY("");
    int iRet = 0;
    __TRY__

    if (!prx)
    {
        ROLLLOG_ERROR << "ManageClubGetClubIDAndPosition prx null!" << endl;
        return -1;
    }

    dbagent::TDBReadReq dataReq;
    dataReq.keyIndex = 0;
    dataReq.queryType = dbagent::E_SELECT;
    dataReq.tableName = "tb_club_member";

    vector<dbagent::TField> fields;
    dbagent::TField tfield;
    tfield.colArithType = E_NONE;
    tfield.colName = "cid";
    fields.push_back(tfield);

    tfield.colArithType = E_NONE;
    tfield.colName = "position";
    fields.push_back(tfield);

    dataReq.fields = fields;

    //where条件组
    vector<dbagent::ConditionGroup> conditionGroups;
    dbagent::ConditionGroup conditionGroup;
    conditionGroup.relation = dbagent::AND;
    vector<dbagent::Condition> conditions;
    dbagent::Condition condition;
    condition.condtion = dbagent::E_EQ;
    condition.colType = dbagent::INT;
    condition.colName = "uid";
    condition.colValues = L2S(uId);
    conditions.push_back(condition);
    conditionGroup.condition = conditions;
    conditionGroups.push_back(conditionGroup);
    dataReq.conditions = conditionGroups;

    dbagent::TDBReadRsp dataRsp;
    iRet = prx->read(dataReq, dataRsp);
    if (iRet != 0 || dataRsp.iResult != 0)
    {
        ROLLLOG_ERROR << "ManageClubGetClubIDAndPosition failed!" << " iRet:" << iRet << ", iResult:" << dataRsp.iResult << ", dataReq:" << printTars(dataReq) << endl;
        return -1;
    }

    for (auto it = dataRsp.records.begin(); it != dataRsp.records.end(); ++it)
    {
        tars::Int64 cid = -1;
        tars::Int32 pos = -1;
        for (auto itTField = it->begin(); itTField != it->end(); ++itTField)
        {
            if (cid != -1 && pos != -1)
            {
                break;
            }

            if (itTField->colName == "cid")
            {
                cid = S2L(itTField->colValue);
            }
            else if (itTField->colName == "position")
            {
                pos = S2I(itTField->colValue);
            }
        }

        if (cid != -1 && pos != -1)
        {
            mClubIds[cid] = pos;
        }
    }

    __CATCH__

    FUNC_EXIT("", iRet);
    return iRet;
}

// 获取俱乐成员UID
tars::Int32 ManageClubGetMemberID(const DBAgentServantPrx prx, tars::Int64 cId, std::vector<long> &vUid)
{
    FUNC_ENTRY("");
    int iRet = 0;
    __TRY__

    if (!prx)
    {
        ROLLLOG_ERROR << "ManageClubGetMemberID prx null!" << endl;
        return -1;
    }

    dbagent::TDBReadReq dataReq;
    dataReq.keyIndex = 0;
    dataReq.queryType = dbagent::E_SELECT;
    dataReq.tableName = "tb_club_member";

    vector<dbagent::TField> fields;
    dbagent::TField tfield;
    tfield.colArithType = E_NONE;
    tfield.colName = "uid";
    fields.push_back(tfield);

    dataReq.fields = fields;

    //where条件组
    vector<dbagent::ConditionGroup> conditionGroups;
    dbagent::ConditionGroup conditionGroup;
    conditionGroup.relation = dbagent::AND;
    vector<dbagent::Condition> conditions;
    dbagent::Condition condition;
    condition.condtion = dbagent::E_EQ;
    condition.colType = dbagent::INT;
    condition.colName = "cid";
    condition.colValues = L2S(cId);
    conditions.push_back(condition);
    conditionGroup.condition = conditions;
    conditionGroups.push_back(conditionGroup);
    dataReq.conditions = conditionGroups;

    dbagent::TDBReadRsp dataRsp;
    iRet = prx->read(dataReq, dataRsp);
    if (iRet != 0 || dataRsp.iResult != 0)
    {
        ROLLLOG_ERROR << "ManageClubGetMemberID failed!" << " iRet:" << iRet << ", iResult:" << dataRsp.iResult <<  ", dataReq:" << printTars(dataReq) << endl;
        return -2;
    }

    for (auto it = dataRsp.records.begin(); it != dataRsp.records.end(); ++it)
    {
        for (auto itTField = it->begin(); itTField != it->end(); ++itTField)
        {
            if (itTField->colName == "uid")
            {
                vUid.push_back(S2L(itTField->colValue));
                break;
            }
        }
    }

    __CATCH__

    FUNC_EXIT("", iRet);
    return iRet;
}

// 检查个人俱乐部权限
tars::Int32 ManageClubCheckPosition(const DBAgentServantPrx prx, tars::Int64 cId, tars::Int64 uId, tars::Int32 position)
{
    FUNC_ENTRY("");
    int iRet = 0;
     __TRY__

    if (!prx)
    {
        ROLLLOG_ERROR << "ManageClubCheckPosition null!" << endl;
        return -1;
    }

    dataproxy::TReadDataReq dataReq;
    dataReq.resetDefautlt();
    dataReq.keyName = I2S(E_REDIS_TYPE_LIST) + ":" + I2S(CLUB_MEMBER_CHECK_POSITION) + ":" + L2S(cId);
    dataReq.operateType = E_REDIS_COUNT;
    dataReq.clusterInfo.resetDefautlt();
    dataReq.clusterInfo.busiType = E_REDIS_PROPERTY;
    dataReq.clusterInfo.frageFactorType = E_FRAGE_FACTOR_USER_ID;
    dataReq.clusterInfo.frageFactor = cId;

    vector<TField> fields;
    dbagent::TField tfield;
    auto &conditionFields = dataReq.paraExt.fields;
    tfield.resetDefautlt();
    tfield.colValue = L2S(uId);
    conditionFields["uid"] = tfield;
    tfield.resetDefautlt();
    tfield.colValue = L2S(position);
    conditionFields["position"] = tfield;

    TReadDataRsp dataRsp;
    iRet = prx->redisRead(dataReq, dataRsp);
    if(iRet != 0 || dataRsp.iResult != 0)
    {
        ROLLLOG_DEBUG << "ManageClubCheckPosition failed!" << " iRet:" << iRet << ", iResult:" << dataRsp.iResult << ", dataReq:" << printTars(dataReq) << endl;
        return -2;
    }

    ROLLLOG_DEBUG << "ManageClubCheckPosition ok!" << " dataReq:" << printTars(dataReq) << ", dataRsp:" << printTars(dataRsp) << endl;

    if (dataRsp.totalcount > 0)
    {
        return 0;
    }

    __CATCH__
    FUNC_EXIT("", iRet);

    return -1;
}

// 获取个人俱乐部职位
tars::Int32 ManageClubGetOwnPosition(const DBAgentServantPrx prx, tars::Int64 cId, tars::Int64 uId, int &position)
{
    FUNC_ENTRY("");
    int iRet = 0;
     __TRY__

    if (!prx)
    {
        ROLLLOG_ERROR << "ManageClubGetOwnPosition prx null!" << endl;
        return -1;
    }
    dataproxy::TReadDataReq dataReq;
    dataReq.resetDefautlt();
    dataReq.keyName = I2S(E_REDIS_TYPE_LIST) + ":" + I2S(CLUB_OWN_POSITION) + ":" + L2S(uId);
    dataReq.operateType = E_REDIS_READ;
    dataReq.clusterInfo.resetDefautlt();
    dataReq.clusterInfo.busiType = E_REDIS_PROPERTY;
    dataReq.clusterInfo.frageFactorType = E_FRAGE_FACTOR_USER_ID;
    dataReq.clusterInfo.frageFactor = uId;

    vector<TField> fields;
    dbagent::TField tfield;
    auto &conditionFields = dataReq.paraExt.fields;
    tfield.resetDefautlt();
    tfield.colValue = L2S(cId);
    conditionFields["cid"] = tfield;

    TReadDataRsp dataRsp;
    iRet = prx->redisRead(dataReq, dataRsp);
    if(iRet != 0 || dataRsp.iResult != 0)
    {
        ROLLLOG_DEBUG << "ManageClubGetOwnPosition failed!" << " iRet:" << iRet << ", iResult:" << dataRsp.iResult << ", dataReq:" << printTars(dataReq) << endl;
        return -2;
    }

    bool isFind = false;
    ROLLLOG_DEBUG << "ManageClubGetOwnPosition ok!" << " dataReq:" << printTars(dataReq) << ", dataRsp:" << printTars(dataRsp) << endl;

    for (auto it = dataRsp.fields.begin(); it != dataRsp.fields.end(); ++it)
    {
        for (auto itfield = it->begin(); itfield != it->end(); ++itfield)
        {
            if (itfield->colName == "position")
            {
                isFind = true;
                position = S2I(itfield->colValue);
                break;
            }
        }
    }

    if (isFind)
    {
        return 0;
    }

    __CATCH__
    FUNC_EXIT("", iRet);

    return -1;
}

// 获取申请信息数量
tars::Int32 ManageClubGetApplyCount(const DBAgentServantPrx prx, tars::Int64 cId, long &count)
{
    FUNC_ENTRY("");
    int iRet = 0;
     __TRY__

    if (!prx)
    {
        ROLLLOG_ERROR << "ManageClubGetApplyCount prx null!" << endl;
        return -1;
    }

    dataproxy::TReadDataReq dataReq;
    dataReq.resetDefautlt();
    dataReq.keyName = I2S(E_REDIS_TYPE_LIST) + ":" + I2S(CLUB_APPLY_LIST) + ":" + I2S(cId);
    dataReq.operateType = E_REDIS_COUNT;
    dataReq.clusterInfo.resetDefautlt();
    dataReq.clusterInfo.busiType = E_REDIS_PROPERTY;
    dataReq.clusterInfo.frageFactorType = E_FRAGE_FACTOR_USER_ID;
    dataReq.clusterInfo.frageFactor = cId;

    vector<TField> fields;
    dbagent::TField tfield;
    auto &conditionFields = dataReq.paraExt.fields;
    tfield.resetDefautlt();
    tfield.colValue = I2S(0);
    conditionFields["status"] = tfield;

    TReadDataRsp dataRsp;
    iRet = prx->redisRead(dataReq, dataRsp);
    if(iRet != 0 || dataRsp.iResult != 0)
    {
        ROLLLOG_ERROR << "ManageClubGetApplyCount failed! iRet:" << iRet << ", iResult:" << dataRsp.iResult << ", dataReq:" << dataReq << endl;
        return -2;
    }

    ROLLLOG_DEBUG << "ManageClubGetApplyCount ok! dataReq:" << printTars(dataReq) << ", dataRsp:" << printTars(dataRsp) << endl;

    if (dataRsp.totalcount > 0)
    {
        count = dataRsp.totalcount;
    }

    __CATCH__
    FUNC_EXIT("", iRet);

    return iRet;
}

// 获取俱乐部单个申请详情
tars::Int32 ManageClubGetApply(const DBAgentServantPrx prx, Club::ClubApplyInfo &info, tars::Int64 id)
{
    FUNC_ENTRY("");
    int iRet = 0;
    __TRY__

    if (!prx)
    {
        ROLLLOG_ERROR << "ManageClubGetApply prx null!" << endl;
        return -1;
    }

    dbagent::TDBReadReq dataReq;
    dataReq.keyIndex = 0;
    dataReq.queryType = dbagent::E_SELECT;
    dataReq.tableName = "tb_club_apply";

    vector<dbagent::TField> fields;
    dbagent::TField tfield;
    tfield.colArithType = E_NONE;
    tfield.colName = "cid";
    fields.push_back(tfield);

    tfield.colArithType = E_NONE;
    tfield.colName = "uid";
    fields.push_back(tfield);

    tfield.colArithType = E_NONE;
    tfield.colName = "status";
    fields.push_back(tfield);

    dataReq.fields = fields;

    //where条件组
    vector<dbagent::ConditionGroup> conditionGroups;
    dbagent::ConditionGroup conditionGroup;
    conditionGroup.relation = dbagent::AND;
    vector<dbagent::Condition> conditions;
    dbagent::Condition condition;
    condition.condtion = dbagent::E_EQ;
    condition.colType = dbagent::BIGINT;
    condition.colName = "id";
    condition.colValues = L2S(id);
    conditions.push_back(condition);
    conditionGroup.condition = conditions;
    conditionGroups.push_back(conditionGroup);
    dataReq.conditions = conditionGroups;

    // 指定返回的行数的最大值
    dataReq.limit = 1;
    // 指定返回的每一行的偏移量
    dataReq.limit_from = 0;

    dbagent::TDBReadRsp dataRsp;
    iRet = prx->read(dataReq, dataRsp);
    if (iRet != 0 || dataRsp.iResult != 0)
    {
        ROLLLOG_ERROR << "ManageClubGetApply failed! iRet:" << iRet << ", iResult:" << dataRsp.iResult << ", dataReq:" << printTars(dataReq) << endl;
        return -1;
    }

    ROLLLOG_DEBUG << "ManageClubGetApply ok! dataReq:" << printTars(dataReq) << ", dataRsp:" << printTars(dataRsp) << endl;

    for (auto it = dataRsp.records.begin(); it != dataRsp.records.end(); ++it)
    {
        for (auto itTField = it->begin(); itTField != it->end(); ++itTField)
        {
            if (itTField->colName == "cid")
            {
                info.cId = S2L(itTField->colValue);
            }
            else if (itTField->colName == "uid")
            {
                info.uId = S2I(itTField->colValue);
            }
            else if (itTField->colName == "status")
            {
                info.status = S2I(itTField->colValue);
            }
        }
    }

    info.id = id;

    __CATCH__
    FUNC_EXIT("", iRet);
    return iRet;
}

// 创建俱乐部申请
tars::Int32 ManageClubInsertApply(const DBAgentServantPrx prx, tars::Int64 cId, tars::Int64 tId, tars::Int64 uId, tars::Int32 status, std::string msg)
{
    FUNC_ENTRY("");
    int iRet = 0;
    __TRY__

    if (!prx)
    {
        ROLLLOG_ERROR << "ManageClubInsertApply prx null!" << endl;
        return -1;
    }

    dataproxy::TWriteDataReq dataReq;
    dataReq.resetDefautlt();
    dataReq.keyName = I2S(E_REDIS_TYPE_LIST) + ":" + I2S(CLUB_APPLY_CREATE) + ":" + L2S(cId);
    dataReq.operateType = E_REDIS_INSERT;
    dataReq.clusterInfo.resetDefautlt();
    dataReq.clusterInfo.busiType = E_REDIS_PROPERTY;
    dataReq.clusterInfo.frageFactorType = E_FRAGE_FACTOR_STRING;
    dataReq.clusterInfo.frageFactor = tars::hash<string>()(L2S(cId));

    vector<TField> fields;
    TField tfield;
    tfield.colArithType = E_NONE;
    tfield.colName = "cid";
    tfield.colType = BIGINT;
    tfield.colValue = L2S(cId);
    fields.push_back(tfield);

    tfield.colName = "tid";
    tfield.colType = BIGINT;
    tfield.colValue = L2S(tId);
    fields.push_back(tfield);

    tfield.colName = "uid";
    tfield.colType = BIGINT;
    tfield.colValue = L2S(uId);
    fields.push_back(tfield);

    tfield.colName = "answer";
    tfield.colType = BIGINT;
    tfield.colValue = L2S(0);
    fields.push_back(tfield);

    tfield.colName = "status";
    tfield.colType = INT;
    tfield.colValue = I2S(status);
    fields.push_back(tfield);

    tfield.colName = "msg";
    tfield.colType = STRING;
    tfield.colValue = msg;
    fields.push_back(tfield);

    tfield.colName = "applied";
    tfield.colType = STRING;
    tfield.colValue = g_app.getOuterFactoryPtr()->GetTLogTimeFormat();
    fields.push_back(tfield);

    dataReq.fields = fields;

    dataproxy::TWriteDataRsp dataRsp;
    iRet = prx->redisWrite(dataReq, dataRsp);
    if (iRet != 0 || dataRsp.iResult != 0)
    {
        ROLLLOG_ERROR << "ManageClubInsertApply failed! iRet:" << iRet << ", iResult:" << dataRsp.iResult << ", dataReq:" << printTars(dataReq) << endl;
        return -2;
    }

    ROLLLOG_DEBUG << "ManageClubInsertApply ok! dataReq:" << printTars(dataReq) << endl;

    __CATCH__
    FUNC_EXIT("", iRet);
    return iRet;
}

// 检测俱乐部申请信息
bool ManageClubCheckApply(const DBAgentServantPrx prx, tars::Int64 cId, tars::Int64 tId, tars::Int64 uId)
{
    FUNC_ENTRY("");
    int iRet = 0;
    __TRY__

    if (!prx)
    {
        ROLLLOG_ERROR << "ManageClubCheckApply prx null!" << endl;
        return false;
    }

    dataproxy::TReadDataReq dataReq;
    dataReq.resetDefautlt();
    dataReq.keyName = I2S(E_REDIS_TYPE_HASH) + ":" + I2S(CLUB_APPLY_UPDATE) + ":" + L2S(cId);
    dataReq.operateType = E_REDIS_COUNT;
    dataReq.clusterInfo.resetDefautlt();
    dataReq.clusterInfo.busiType = E_REDIS_PROPERTY;
    dataReq.clusterInfo.frageFactorType = E_FRAGE_FACTOR_USER_ID;
    dataReq.clusterInfo.frageFactor = cId;

    vector<TField> fields;
    dbagent::TField tfield;
    auto &conditionFields = dataReq.paraExt.fields;
    tfield.resetDefautlt();
    tfield.colValue = L2S(tId);
    conditionFields["tid"] = tfield;
    tfield.colValue = L2S(uId);
    conditionFields["uid"] = tfield;
    tfield.colValue = I2S(0);
    conditionFields["status"] = tfield;

    TReadDataRsp dataRsp;
    iRet = prx->redisRead(dataReq, dataRsp);
    if(iRet != 0 || dataRsp.iResult != 0)
    {
        ROLLLOG_ERROR << "ManageCheckClubApply failed! iRet:" << iRet << ", iResult:" << dataRsp.iResult << ", dataReq:" << printTars(dataReq) << endl;
        return false;
    }

    ROLLLOG_DEBUG << "ManageCheckClubApply ok! dataReq:" << printTars(dataReq) << ", dataRsp:" << printTars(dataRsp) << endl;
    if (dataRsp.totalcount > 0)
    {
        return true;
    }
  
    __CATCH__
    FUNC_EXIT("", iRet);

    return false;
}

// 更新俱乐部申请
tars::Int32 ManageClubUpdateApply(const DBAgentServantPrx prx, tars::Int64 cId, tars::Int64 tId, tars::Int64 uId, std::string msg)
{
    FUNC_ENTRY("");
    int iRet = 0;
    __TRY__

    if (!prx)
    {
        ROLLLOG_ERROR << "ManageClubUpdateApply prx null!" << endl;
    	return -1;
    }

    dataproxy::TWriteDataReq dataReq;
    dataReq.resetDefautlt();
    dataReq.keyName = I2S(E_REDIS_TYPE_LIST) + ":" + I2S(CLUB_APPLY_UPDATE) + ":" + L2S(cId);
    dataReq.operateType = E_REDIS_WRITE;
    dataReq.paraExt.resetDefautlt();
    dataReq.paraExt.queryType = dbagent::E_UPDATE;
    dataReq.clusterInfo.resetDefautlt();
    dataReq.clusterInfo.busiType = E_REDIS_PROPERTY;
    dataReq.clusterInfo.frageFactorType = E_FRAGE_FACTOR_USER_ID;
    dataReq.clusterInfo.frageFactor = cId;

    vector<TField> fields;
    dbagent::TField tfield;
    tfield.resetDefautlt();
    tfield.colArithType = E_NONE;
    tfield.colName = "msg";
    tfield.colType = STRING;
    tfield.colValue = msg;
    fields.push_back(tfield);

    tfield.colArithType = E_NONE;
    tfield.colName = "applied";
    tfield.colType = STRING;
    tfield.colValue = g_app.getOuterFactoryPtr()->GetTLogTimeFormat();
    fields.push_back(tfield);

    dataReq.fields = fields;

    auto &conditionFields = dataReq.paraExt.fields;
    tfield.resetDefautlt();
    tfield.colValue = L2S(cId);
    conditionFields["tid"] = tfield;
    tfield.colValue = L2S(uId);
    conditionFields["uid"] = tfield;
    tfield.colValue = I2S(0);
    conditionFields["status"] = tfield;

    dataproxy::TWriteDataRsp dataRsp;
    iRet = prx->redisWrite(dataReq, dataRsp);
    if (iRet != 0 || dataRsp.iResult != 0)
    {
        ROLLLOG_ERROR << "ManageClubUpdateApply failed! iRet:" << iRet << ", iResult:" << dataRsp.iResult << ", dataReq:" << printTars(dataReq) << endl;
        return -2;
    }

    ROLLLOG_DEBUG << "ManageClubUpdateApply ok! dataReq:" << printTars(dataReq) << ", dataRsp:" << printTars(dataRsp) << endl;

    __CATCH__
    FUNC_EXIT("", iRet);
    return iRet;
}

// 修改俱乐部申请信息
tars::Int32 ManageClubModifyApply(const DBAgentServantPrx prx, tars::Int64 id, tars::Int64 uId, tars::Int32 status)
{
    FUNC_ENTRY("");
    int iRet = 0;
    __TRY__

    if (!prx)
    {
        ROLLLOG_ERROR << "ManageClubModifyApply prx null!" << endl;
    	return -1;
    }

    dbagent::TDBWriteReq dataReq;
    dataReq.keyIndex = 0;
    dataReq.queryType = dbagent::E_UPDATE;
    dataReq.tableName = "tb_club_apply";

    vector<dbagent::TField> fields;
    dbagent::TField tfield;
    tfield.colArithType = E_NONE;

    tfield.colName = "answer";
    tfield.colType = dbagent::BIGINT;
    tfield.colValue = L2S(uId);
    fields.push_back(tfield);

    tfield.colName = "status";
    tfield.colType = dbagent::BIGINT;
    tfield.colValue = I2S(status);
    fields.push_back(tfield);

    dataReq.fields = fields;

    //where条件组
    vector<dbagent::ConditionGroup> conditionGroups;
    dbagent::ConditionGroup conditionGroup;
    conditionGroup.relation = dbagent::AND;
    vector<dbagent::Condition> conditions;
    dbagent::Condition condition;
    condition.condtion = dbagent::E_EQ;
    condition.colType = dbagent::BIGINT;
    condition.colName = "id";
    condition.colValues = L2S(id);
    conditions.push_back(condition);
    conditionGroup.condition = conditions;
    conditionGroups.push_back(conditionGroup);
    dataReq.conditions = conditionGroups;

    dbagent::TDBWriteRsp dataRsp;
    iRet = prx->write(dataReq, dataRsp);
    if (iRet != 0 || dataRsp.iResult != 0)
    {
        ROLLLOG_ERROR << "ManageClubModifyApply failed!  iRet:" << iRet << ", iResult:" << dataRsp.iResult << ", dataReq:" << printTars(dataReq) << ", dataRsp: " << printTars(dataRsp) << endl;
        return -2;
    }

    ROLLLOG_DEBUG << "ManageClubModifyApply ok! dataReq:" << printTars(dataReq) << ", dataRsp:" << printTars(dataRsp) << endl;

    __CATCH__
    FUNC_EXIT("", iRet);
    return iRet;
}

// 更新俱乐部保险保证基金
tars::Int32 ModifyClubFund(const DBAgentServantPrx prx, tars::Int64 cId, bool isAdd, int level, long fund)
{
    FUNC_ENTRY("");
    int iRet = 0;
    __TRY__

    if (!prx)
    {
        ROLLLOG_ERROR << "ModifyClubFund prx null!" << endl;
        return -1;
    }

    dataproxy::TWriteDataReq dataReq;
    dataReq.resetDefautlt();
    dataReq.keyName = I2S(E_REDIS_TYPE_HASH) + ":" + I2S(CLUB_INFO_UPDATE) + ":" + L2S(cId);
    dataReq.operateType = E_REDIS_WRITE;
    dataReq.paraExt.resetDefautlt();
    dataReq.paraExt.queryType = dbagent::E_UPDATE;
    dataReq.clusterInfo.resetDefautlt();
    dataReq.clusterInfo.busiType = E_REDIS_PROPERTY;
    dataReq.clusterInfo.frageFactorType = E_FRAGE_FACTOR_USER_ID;
    dataReq.clusterInfo.frageFactor = cId;

    vector<TField> fields;
    TField tfield;
    tfield.colName = "merchant_level";
    tfield.colType = INT;
    tfield.colValue = I2S(level);
    fields.push_back(tfield);

    if (isAdd)
    {
        tfield.colArithType = E_ADD;
    }
    else
    {
        tfield.colArithType = E_SUB;
    }
        
    tfield.colName = "fund";
    tfield.colType = BIGINT;
    tfield.colValue = L2S(fund);
    fields.push_back(tfield);
   
    dataReq.fields = fields;

    dataproxy::TWriteDataRsp dataRsp;
    iRet = prx->redisWrite(dataReq, dataRsp);
    if (iRet != 0 || dataRsp.iResult != 0)
    {
        ROLLLOG_ERROR << "modify club fund err, iRet: " << iRet << ", iResult: " << dataRsp.iResult << endl;
        return -2;
    }

    ROLLLOG_DEBUG << "modify club fund, iRet: " << iRet << ", dataRsp: " << printTars(dataRsp) << endl;

    __CATCH__
    FUNC_EXIT("", iRet);
    return iRet;
}

// 更新俱乐部商户等级
tars::Int32 ModifyClubMerchantLevel(const DBAgentServantPrx prx, tars::Int64 cId, int level)
{
    FUNC_ENTRY("");
    int iRet = 0;
    __TRY__

    if (!prx)
    {
        ROLLLOG_ERROR << "ModifyClubMerchantLevel prx null!" << endl;
        return -1;
    }

    dataproxy::TWriteDataReq dataReq;
    dataReq.resetDefautlt();
    dataReq.keyName = I2S(E_REDIS_TYPE_HASH) + ":" + I2S(CLUB_INFO_UPDATE) + ":" + L2S(cId);
    dataReq.operateType = E_REDIS_WRITE;
    dataReq.paraExt.resetDefautlt();
    dataReq.paraExt.queryType = dbagent::E_UPDATE;
    dataReq.clusterInfo.resetDefautlt();
    dataReq.clusterInfo.busiType = E_REDIS_PROPERTY;
    dataReq.clusterInfo.frageFactorType = E_FRAGE_FACTOR_USER_ID;
    dataReq.clusterInfo.frageFactor = cId;

    vector<TField> fields;
    TField tfield;
    tfield.colName = "merchant_level";
    tfield.colType = INT;
    tfield.colValue = I2S(level);
    fields.push_back(tfield);
   
    dataReq.fields = fields;

    dataproxy::TWriteDataRsp dataRsp;
    iRet = prx->redisWrite(dataReq, dataRsp);
    if (iRet != 0 || dataRsp.iResult != 0)
    {
        ROLLLOG_ERROR << "modify club merchant_level err, iRet: " << iRet << ", iResult: " << dataRsp.iResult << endl;
        return -2;
    }

    ROLLLOG_DEBUG << "modify club merchant_level, iRet: " << iRet << ", dataRsp: " << printTars(dataRsp) << endl;

    __CATCH__
    FUNC_EXIT("", iRet);
    return iRet;
}